import Vue from "vue";
import Router from "vue-router";

import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import VueRouter from "vue-router";

// 配置顶部加载进度条
NProgress.configure({
    easing: 'ease', // 动画方式
    speed: 400, // 递增进度条的速度
    showSpinner: true, // 是否显示加载ico
    trickleSpeed: 200, // 自动递增间隔
    minimum: 0.3 // 初始化时的最小百分比
});

Vue.use(Router);

const router = new VueRouter(
    {
        routes: [
            {
                path: "/",
                name: "",
                redirect: 'login'
            },
            {
                path: "/login",
                name: "login",
                component: resolve => (require(["@/pages/login"], resolve)),
            },
            {
                path: "/dashboard",
                name: "dashboard",
                component: resolve => (require(["@/pages/layout"], resolve)),
                children: [
                    {
                        path: '/workplace',
                        name: 'workplace',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/dashboard/workplace"], resolve)),
                    },
                    {
                        path: '/analysis',
                        name: 'analysis',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/dashboard/analysis"], resolve)),
                    },
                    {
                        path: '/blackhole',
                        name: 'blackhole',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/css-demo/blackhole"], resolve)),
                    },
                    {
                        path: '/waveText',
                        name: 'waveText',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/css-demo/waveText"], resolve)),
                    },
                    {
                        path: '/highWay',
                        name: 'highWay',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/css-demo/highWay"], resolve)),
                    },
                    {
                        path: '/scrollProgress',
                        name: 'scrollProgress',
                        meta: { zIndex: 1 },
                        component: resolve => (require(["@/pages/css-demo/css-scroll-progress"], resolve)),
                    },
                    // 
                ]
            }
        ]
    }
);


// 防止重复点击报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 增加页面切换动画效果
router.beforeEach((to, from, next) => {
    NProgress.start();
    next();
});
router.afterEach(() => {
    NProgress.done()
});

export default router;
